package com.alks.function.controller.stockdept.pcfactorystockquery;

import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.WebLogger;
import com.alks.entity.data.entity.PcCuttingCollectDetail;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.data.dto.biocontrol.webwork.RecIoBatchRequest;
import com.alks.function.data.request.factoryquery.CuttingPartRequest;
import com.alks.function.data.request.stockdept.pcfactorystockwork.CuttingRceIoBackRequest;
import com.alks.function.data.request.stockdept.pcfactorystockwork.CuttingRecDetRequest;
import com.alks.function.data.request.stockdept.pcfactorystockwork.CuttingRecIoRequest;
import com.alks.function.data.request.stockdept.pcfactorystockwork.CuttingRecTempRequest;
import com.alks.function.service.stockdept.pcfactorystockquery.ICuttingRecService;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * @author MS
 * @since 2024/6/28下午4:59
 */
@RestController
@ApiRestController("/pcFactorStockQuery")
@Api(value = "仓储部", tags = "仓储部-仓储工厂作业-冲裁收发作业")
@Slf4j
public class PunchRecController {
    @Autowired
    private ICuttingRecService service;

    private final String processCode = "01";


    @WebLogger
    @PostMapping("/punchRecTempQuery")
    @ApiOperation(value = "冲裁收发查询-可条件分页查询", tags = "仓储部-仓储工厂作业-冲裁收发作业")
    public ResponseInfo punchRecTempQuery(@RequestBody CuttingRecTempRequest request) {
        return service.cuttingRecTempQuery(request,processCode);
    }

    @WebLogger
    @PostMapping("/punchRecDetQuery")
    @ApiOperation(value = "冲裁收发明细查询-条件分页查询", tags = "仓储部-仓储工厂作业-冲裁收发作业")
    public ResponseInfo punchRecDetQuery(@RequestBody@Valid CuttingRecDetRequest request) {
        return service.cuttingRecDetQuery(request, processCode);
    }

    @WebLogger
    @PostMapping("/punchInDateQuery")
    @ApiOperation(value = "日期总览查询-条件查询", tags = "仓储部-仓储工厂作业-冲裁收发作业")
    public ResponseInfo punchInDateQuery(@RequestParam@ApiParam(value = "日期",required = true)
                                           @DateTimeFormat(pattern = "yyyy-MM-dd")
                                           @JsonFormat(timezone = "GMT+8")
                                           LocalDate dateInfo) {
        return service.cuttingInDateQuery(dateInfo.atStartOfDay(), processCode);
    }

    @WebLogger
    @PostMapping("/punchRecDetBack")
    @ApiOperation(value = "冲裁收发明细回显-回显", tags = "仓储部-仓储工厂作业-冲裁收发作业")
    public ResponseInfo punchRecDetBack() {
        return service.cuttingRecDetBack();
    }

    @WebLogger
    @PostMapping("/punchRecIoBack")
    @ApiOperation(value = "冲裁收发回显-回显", tags = "仓储部-仓储工厂作业-冲裁收发作业")
    public ResponseInfo punchRecIoBack(@Valid@RequestBody CuttingRceIoBackRequest request) {
        return service.cuttingRecIoBack(request, processCode);
    }

    @WebLogger
    @PostMapping("/punchRecIoTempBack")
    @ApiOperation(value = "冲裁收发表单回显-回显", tags = "仓储部-仓储工厂作业-冲裁收发作业")
    public ResponseInfo punchRecIoTempBack(@Valid@RequestBody CuttingRceIoBackRequest request) {
        return service.cuttingRecIoTempBack(request, processCode);
    }

    @WebLogger
    @PostMapping("/punchRecDetIo")
    @ApiOperation(value = "冲裁收发料新增-新增", tags = "仓储部-仓储工厂作业-冲裁收发作业")
    public ResponseInfo punchRecDetIo(@Valid@RequestBody List<CuttingRecIoRequest> request,
                                      @RequestHeader(value = "Accept-Language", defaultValue = "zh") String language) {
        return service.cuttingRecDetIo(request, processCode, language);
    }

    @WebLogger
    @PostMapping("/punchRecDetDelete")
    @ApiOperation(value = "冲裁收发删除-删除", tags = "仓储部-仓储工厂作业-冲裁收发作业")
    public ResponseInfo punchRecDetDelete(@RequestBody PcCuttingCollectDetail request) {
        //MS TODO 2024/10/15 : 删除太慢（触发器的问题）
        return service.cuttingRecDetDelete(request, processCode);
    }

    @WebLogger
    @PostMapping("/cuttingScanCodeQuery")
    @ApiOperation(value = "扫码查询-条件查询", tags = "仓储部-仓储工厂作业-冲裁收发作业")
    public ResponseInfo cuttingScanCodeQuery(@RequestParam@ApiParam(required = true,value = "标签") String labelNo,
                                          @RequestParam@ApiParam(required = true,value = "工艺") String processName,
                                             @RequestParam@ApiParam(required = true,value = "收发类型：I 收料，O 发料（字母）") String flag,
                                             @RequestHeader(value = "Accept-Language", defaultValue = "zh") String language) {
        return service.cuttingScanCodeQuery(labelNo, processName,flag,language);
    }

    @WebLogger
    @PostMapping("/cuttingScanLotNoQuery")
    @ApiOperation(value = "扫码指令明细查询-条件查询", tags = "仓储部-仓储工厂作业-冲裁收发作业")
    public ResponseInfo cuttingScanLotNoQuery(@RequestBody@ApiParam CuttingPartRequest request,
                                              @RequestHeader(value = "Accept-Language", defaultValue = "zh") String language) {
        return service.cuttingScanLotNoQuery(request,language);
    }

    @WebLogger
    @PostMapping("/cuttingBatchQuery")
    @ApiOperation(value = "批次查询-查询", tags = "仓储部-仓储工厂作业-冲裁收发作业")
    public ResponseInfo cuttingBatchQuery(@RequestBody RecIoBatchRequest request) {
        List<Map<String,Object>> batchList = service.batchQuery(request, processCode);
        return ResponseInfo.ok(batchList);
    }

}